<include file="Public/header" />
<include file="Public/menu" />
<link rel="stylesheet" href="/Public/admin/adminlte/bootstrap/css/bootstrap-switch.min.css">
<!-- 内容页 -->
<div class="content-wrapper">
    <!-- 面包屑 -->
    <section class="content-header">
        <h1>
            首页管理
            <small>热门搜索</small>
        </h1>
        <ol class="breadcrumb">
            <li><a href="#"><i class="fa fa-dashboard"></i> 首页管理</a></li>
            <li class="active">热门搜索列表</li>
        </ol>
    </section>

    <!-- 内容 -->
    <section class="content"><div class="row"><div class="col-md-12"><div class="box">
        <div class="box-header">
            <h3 class="box-title">搜索关键字列表</h3>

            <div class="form-inline pull-right">
                <form action="" method="get" pjax-container="">
                    <fieldset>
                        <div class="input-group input-group-sm">
                            <span class="input-group-addon"><strong>名称</strong></span>
                            <input type="hidden" name="$search_field" value="{$search_field|default=name}">
                            <input type="text" class="form-control" placeholder="搜索名称" name="search" value="{$search}">
                        </div>

                        <div class="input-group input-group-sm">
                            <div class="input-group-btn">
                                <button type="submit" class="btn btn-primary"><i class="fa fa-search"></i></button>
                            </div>
                        </div>

                    </fieldset>
                </form>
            </div>


            <div class="btn-group pull-right" style="margin-right: 10px">
                <a href="{:U('add')}" class="btn btn-sm btn-success"><i class="fa fa-save"></i>&nbsp;&nbsp;新增</a>
            </div>

        </div>
        <!-- /.box-header -->
        <div class="box-body table-responsive no-padding">
            <table class="table table-hover">
                <tbody>
                <tr>
                    <th><input type="checkbox" class="grid-select-all"></th>
                    <th>ID</th>
                    <th>搜索名称</th>
                    <th>搜索值(逗号分割)</th>
                    <th>状态</th>
                    <th>操作</th>
                </tr>
                <foreach name="list" item="v" >
                <tr>
                    <td><input type="checkbox" class="grid-item" data-id="{$v.id}"></td>
                    <td>{$v.id}</td>
                    <td>{$v.name}</td>
                    <td>{$v.keywords}</td>
                    <td>
                        <div class="switch">
                            <input type="checkbox" name="state" data-size="mini" data-id="{$v.id}" data-on-text="开" data-off-text="关" <if condition="$v['state'] eq 1 ">checked</if>>
                        </div>
                    </td>
                    <td>
                        <a href="{:U('edit', array('id'=>$v['id']), '')}"><i class="fa fa-edit"></i></a>
                        <a onclick="if(confirm('确定删除?')==false)return false;" href="javascript:void(0)" data-id="{$v.id}" class="_delete"><i class="fa fa-trash"></i></a>
                    </td>
                </tr>
                </foreach>

                </tbody>
            </table>
        </div>
        <div class="box-footer clearfix">
            <input type="checkbox" class="grid-select-all">&nbsp;&nbsp;&nbsp;
            <a class="btn btn-sm btn-danger batch-delete">批量删除</a>
            <a class="btn btn-sm btn-primary grid-refresh"><i class="fa fa-refresh"></i></a>

        </div>

        <!-- /.box-body -->
    </div></div></div>

    </section>
</div>
<!-- 底部 -->
<include file="Public/common_footer" />
<script src="__PUBLIC__/Qgs/Qgslte/bootstrap/js/bootstrap-switch.min.js"></script>
<script>

    $(function(argument) {
        $('.grid-select-all').change(function () {
            if (this.checked) {
                $('.grid-item').prop("checked", true);
            } else {
                $('.grid-item').prop("checked", false);
            }
        });

        $('.switch [type="checkbox"]').bootstrapSwitch();

        $('input[name="state"]').on('switchChange.bootstrapSwitch', function (event, state) {
            var id = $(this).attr('data-id');
            $.ajax({
                type: 'get',
                url: "{:U('change')}",
                data: {id: id, state: state},
                success: function (msg) {

                },
                error: function (msg) {
                    alert(msg.message);
                }
            })
        });

        $('._delete').on('click', function () {
            var id = $(this).attr('data-id');
            $.ajax({
                type: 'post',
                url: "{:U('delete')}",
                data: {id: id},
                success: function (msg) {
                    window.location.reload();
                },
                error: function (msg) {
                    alert(msg.message);
                }
            })
        });

        $('.batch-delete').on('click',function(e){
            if(!confirm("确认批量删除")){
                return false;
            }
            var data = [];
            $(".grid-item[type='checkbox']:checked").each(function (i) {
                var id = $(this).attr('data-id');
                data.push(id);
                //$(this).parent().parent().remove();
            });
            if (data) {
                $.ajax({
                    type: "post",
                    url: "{:U('delete')}",
                    data: {id:data},
                    success: function(msg){
                        window.location.reload();
                    },
                    error: function (msg) {
                        alert(msg.message);
                    }
                });
            }
        });
    })
</script>
